﻿using System.Collections;

using Storm.TextEditor.Drawing.GDI;

namespace Storm.TextEditor.Core
{
    public class MemoryHandler
    {
        #region Fields

        private static ArrayList heap = new ArrayList();

        #endregion

        #region Properties

        public static GDIObject[] Items
        {
            get
            {
                ArrayList al = new ArrayList();

                foreach (GDIObject go in heap)
                {
                    if (go != null)
                        al.Add(go);
                }

                GDIObject[] gos = new GDIObject[al.Count];
                al.CopyTo(0, gos, 0, al.Count);

                return gos;
            }
        }

        #endregion

        #region Methods

        #region Public

        public static void Add(GDIObject item)
        {
            heap.Add(item);
        }

        public static void Remove(GDIObject item)
        {
            if (heap.Contains(item))
                heap.Remove(item);
        }

        public static void DestroyAll()
        {
            foreach (GDIObject go in Items)
                go.Dispose();
        }

        #endregion

        #endregion
    }
}
